package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.ProdcutSpec;
import com.atguigu.spzx.model.result.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/spec")
@Tag(name = "商品规格参数管理模块")
public class ProductSpecController {
    @Resource
    ProductSpecService productSpecService;
    @Operation(summary = "查询所有规格参数")
    @GetMapping("list")
    public Result listAll(){
        List<ProdcutSpec> list = productSpecService.listAll();
        return Result.ok(list);
    }
    @Operation(summary = "根据id查询规格参数")
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable("id")Long id){
        //删除时也可能前端需要得到删除的行数据
        ProdcutSpec prodcutSpec = productSpecService.getById(id);
        return Result.ok(prodcutSpec);
    }
    @Operation(summary = "更新规格参数")
    @PutMapping("update")
    public Result update(@RequestBody ProdcutSpec prodcutSpec){
        productSpecService.update(prodcutSpec);
        return Result.ok();
    }
    @Operation(summary = "新增规格参数")
    @PostMapping("save")
    public Result save(@RequestBody ProdcutSpec prodcutSpec){
        productSpecService.save(prodcutSpec);
        return Result.ok();
    }

    @Operation(summary = "删除指定规格参数")
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id")Long id){
        //删除时也可能前端需要得到删除的行数据
        productSpecService.deleteById(id);
        return Result.ok();
    }
    @Operation(summary = "查询规格参数分页数据")
    @GetMapping("list/{pageNum}/{pageSize}")
    public Result list(@PathVariable("pageNum") Integer pageNum ,
                       @PathVariable("pageSize")  Integer pageSize){
        PageInfo<ProdcutSpec> page = productSpecService.list(pageNum,pageSize);
        return Result.ok(page);
    }
}
